home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / tests / stdioCopy / RCS / copy.c,v < prev   
Encoding:
Text File  |  1992-07-17  |  1.5 KB  |  85 lines

  1. head     1.1;
  2. branch   ;
  3. access   ;
  4. symbols  srv030:1.1 srv027:1.1 srv026:1.1 srv024:1.1 srv021:1.1 srv018:1.1 srv014:1.1 srv010:1.1 srv008:1.1 srv007:1.1 srv006:1.1 srv004:1.1;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.1
  10. date     91.12.12.22.45.52;  author kupfer;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @Test copy program, using stdio.
  17. @
  18.  
  19.  
  20.  
  21. 1.1
  22. log
  23. @Initial revision
  24. @
  25. text
  26. @/* Yet another test copy program, this time using stdio. */
  27.  
  28. #ifndef lint
  29. static char rcsid[] = "$Header$";
  30. #endif
  31.  
  32. #include <sprite.h>
  33. #include <stdio.h>
  34. #include <stdlib.h>
  35.  
  36. static void CopyFile();
  37.  
  38. int
  39. main(argc, argv)
  40.     int argc;
  41.     char *argv[];
  42. {
  43.     if (argc != 3) {
  44.     fprintf(stderr, "usage: copy from to\n");
  45.     exit(1);
  46.     }
  47.     CopyFile(argv[1], argv[2]);
  48.     
  49.     return 0;
  50. }
  51.  
  52. static void
  53. CopyFile(fromFileName, toFileName)
  54.     char *fromFileName;
  55.     char *toFileName;
  56. {
  57.     FILE *fromPtr;
  58.     FILE *toPtr;
  59.     Address buffer;
  60.     int bufferSize;        /* number of bytes in buffer */
  61.  
  62.     fromPtr = fopen(fromFileName, "r");
  63.     if (fromPtr == NULL) {
  64.     fprintf(stderr, "Can't open %s for reading\n", fromFileName);
  65.     exit(1);
  66.     }
  67.     toPtr = fopen(toFileName, "w+");
  68.     if (toPtr == NULL) {
  69.     fprintf(stderr, "Can't open %s for writing\n", toFileName);
  70.     exit(1);
  71.     }
  72.  
  73.     bufferSize = 512;
  74.     buffer = malloc(bufferSize);
  75.     if (buffer == NULL) {
  76.     fprintf(stderr, "Couldn't malloc buffer\n");
  77.     exit(1);
  78.     }
  79.  
  80.     while (fgets(buffer, bufferSize, fromPtr) != NULL) {
  81.     fputs(buffer, toPtr);
  82.     }
  83. }
  84. @
  85.